package com.burgeon.backend.SHOPBACKEND.rest;

import com.burgeon.backend.Rest.base.RESTBase;
import com.burgeon.backend.SHOP.entity.RefundErpVO;
import com.burgeon.backend.SHOPBACKEND.entity.FOrder;
import org.json.JSONArray;
import org.springframework.util.MultiValueMap;

import java.util.ArrayList;
import java.util.HashMap;

/*云仓订单发货单,根据提交状态为1 ，没有快递公司的信息,已推送过的*/
public class QuerryYcRetRetailById extends RESTBase {

    private String ip;
    private String account;
    private String password;

    public QuerryYcRetRetailById(String ip, String account, String password) {
        this.ip = ip;
        this.account = account;
        this.password = password;
    }


    /**
     * 发送并接收字符创
     * @return
     */

    public RefundErpVO getData(String id) throws Exception {
        String url = "http://" + ip + "/servlets/binserv/Rest";
        String str = RESULT(Data(id), url);
        //System.err.println(str);
        String code = new JSONArray(str).getJSONObject(0).getString("code");
        if (!"0".equals(code)) {
            throw new Exception(str);
        }
        String count = new JSONArray(str).getJSONObject(0).getString("count");
        JSONArray jsonArray = new JSONArray(str).getJSONObject(0).getJSONArray("rows");

        //JSONArray array = jsonArray.getJSONArray(i);

        RefundErpVO refundErpVO = new RefundErpVO();

        refundErpVO.setDoNo(jsonArray.getJSONArray(0).getString(0));
        refundErpVO.setXsRetNo(jsonArray.getJSONArray(0).getString(1));
        refundErpVO.setYcDoNo(jsonArray.getJSONArray(0).getString(2));

        return refundErpVO;
    }

    private MultiValueMap Data(String id) {
        HashMap params = new HashMap();
        ArrayList columns = new ArrayList();//查询字段

        columns.add("DOCNO");//订单编号
        columns.add("XSRETNO");//线上退货单号
        columns.add("YC_RETAIL_ID");//原云仓订单


        params.put("columns", columns);
        params.put("table", "YC_V2_RET_RETAIL");//表名

        params.put("count","true");

        HashMap paramss = new HashMap();//DOCNO  (AK)	单据编号

        String status = "'"+id+"'";
        paramss.put("column", "ID");
        paramss.put("condition", status);

        params.put("params", paramss);
        //System.err.println(params);

        return DATA("Query", params,account,password);
    }

    public static void main(String[] args) {
        QuerryYcRetRetailById querryYCRetailout = new QuerryYcRetRetailById("59.110.28.94:90", "nea@burgeon.com.cn", "burgeon55321");
        try {
            System.err.println(querryYCRetailout.getData("234"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
